package ptij.vocoder.baseModel.open_loop;

import ptolemy.actor.*;
import ptolemy.kernel.*;
import ptolemy.kernel.util.*;
import ptolemy.data.ObjectToken;
import ptolemy.data.BooleanToken;
import ptolemy.data.expr.Parameter;
import ptolemy.data.type.*;

import ptij.vocoder.baseModel.*;

//////////////////////////////////////////////////////////////////////////
//// PeriodUpd
/**

@author Ivan Jeukens
@version v 0.1 07/08/2003
*/
public class PeriodUpd extends TypedAtomicActor {

    public PeriodUpd(CompositeEntity container, String name) throws
            IllegalActionException, NameDuplicationException {
        super(container, name);

        lags = new TypedIOPort(this, "lags", true, false);
        lags.setTypeEquals(BaseType.OBJECT);

        reset = new TypedIOPort(this, "reset", true, false);
        reset.setTypeEquals(BaseType.BOOLEAN);

        ptch = new TypedIOPort(this, "ptch", false, true);
        ptch.setTypeEquals(BaseType.BOOLEAN);

        dtx_mode = new Parameter(this, "dtx_mode", new BooleanToken(false));
    }

    ///////////////////////////////////////////////////////////////////
    ////                     ports and parameters                  ////

    // Input ports
    public TypedIOPort lags;
    public TypedIOPort reset;

    // Output Ports
    public TypedIOPort ptch;

    public Parameter dtx_mode;

    ///////////////////////////////////////////////////////////////////
    ////                         public methods                    ////

    public void initialize() throws IllegalActionException {
        super.initialize();
        _init();
    }
    
    public void fire() throws IllegalActionException {
        if(reset.hasToken(0)) {
            reset.get(0);
            _init();
        }

        if(!_dtx_mode) return;

        ObjectToken obj = (ObjectToken) lags.get(0);
        Short [] arg1 = (Short []) obj.getValue();

        boolean ret = _period_upd(arg1);

        ptch.broadcast(new BooleanToken(ret));
    }

    ///////////////////////////////////////////////////////////////////
    ////                         private methods                   ////

    private boolean _period_upd(Short [] kags) {
        
        
        return true;
    }

    private void _init() throws IllegalActionException {
        BooleanToken bt = (BooleanToken) dtx_mode.getToken();
        _dtx_mode = bt.booleanValue();

    }

    ///////////////////////////////////////////////////////////////////
    ////                         private variables                 ////

    private boolean _dtx_mode;
}
